// pages/account/index.js
const app = getApp();
Page({

     /**
      * 页面的初始数据
      */
	data: {
		userInfo: {},
		my_reward_person: 0,
		my_reward_money: { mag: 0, rmb: 0 },
		data: {},
		page: 1, //当前页码
		is_wxpay:0,
		setting:{},
          userInfo1:{}
	},

     /**
      * 生命周期函数--监听页面加载
      */
	onLoad: function (options) {
		let that = this;
		//是否开启微信支付
		app.connect('index/setting', {}, function (res) {
			that.setData({
				is_wxpay: res.is_wxpay,
				setting: res
			})
		});
		var uid = options.uid;
		app.login(function (userInfo) {
			if (userInfo != null) {
				that.setData({
					userInfo1: userInfo.data,
					isLogin: true
				});

			}

               console.log(that.data.userInfo1);
			//加载首页推荐信息

			var userLogin = [];
			if (that.data.userInfo1.uid != null && that.data.userInfo1.openId != null) {
				userLogin['uid'] = that.data.userInfo1.uid;
				userLogin['openid'] = that.data.userInfo1.openId;
			}

			app.connect('my/get_userInfo', { uid: uid }, function (userInfo) {
				console.log(userInfo);
				that.setData({
					userInfo: userInfo
				});
				//收到的赞赏人数
				app.connect('my/my_reward_person', {
					uid: that.data.userInfo.uid
				}, function (e) {
					that.setData({
						my_reward_person: e
					})
				});
				//收入
				app.connect('my/my_reward_money', {
					uid: that.data.userInfo.uid
				}, function (e) {
					that.setData({
						my_reward_money: e
					})
				}, true);
				userLogin['my_uid'] = that.data.userInfo.uid; 
				//数据列表
				app.connect('content/index', userLogin, function (e) {
					that.setData({
						data: e.data
					})
					console.log(e);
				});
			});

		})

	},



     /**
      * 页面上拉触底事件的处理函数
      */
	onReachBottom: function (e) {
		let that = this;
		app.connect('content/index', {
			my_uid: that.data.userInfo.uid,
			page: that.data.page + 1
		}, function (e) {
			console.log(e);
			if (e.data.length == 0) {
				wx.showToast({
					title: '到底啦',
					icon: 'none'
				})
				return false;
			}
			var data = that.data.data;
			that.setData({
				data: data.concat(e.data),
				page: that.data.page + 1
			})

		}, true);
	},

     /**
      * 用户点击右上角分享
      */
	onShareAppMessage: function () {

	},
	/**
	 * 点击申请
	 */
	shenqing: function (e) {
		let that = this;
		var content_id = e.currentTarget.dataset.content_id;
		var index = e.currentTarget.dataset.index;
		app.connect('account/shenqing', {
			uid: that.data.userInfo.uid,
			openid: that.data.userInfo.openId,
			content_id: content_id
		}, function (options) {
			var data = that.data.data;
			data[index].is_apply = 1;
			//加载数据
			that.setData({
				data: data
			})
		}, true);
	},
	//转发
	onShareAppMessage: function (res) {
		let that = this;
		if (res.from == 'menu') {
			return {
                    title: '帅哥美女潮人红人都在玩',
				path: 'pages/index/index',
			}
		}
		var content_id = res.target.dataset.content_id;
		var imgUrl = res.target.dataset.imgurl;
		var nick = res.target.dataset.nick;
		console.log(res);
		return {
			title: '@' + nick + ' 在麦颜值发表的作品',
			path: 'pages/look/index?content_id=' + content_id + '&type=1',
			imageUrl: imgUrl
		}
	},
	lookImg: function (e) {

		var content_id = e.currentTarget.dataset.content_id;
		var img_id = e.currentTarget.dataset.img_id;
		wx.navigateTo({
			url: '../look/index?content_id=' + content_id + "&img_id=" + img_id,
		})
	}
})